package com.hmall.api.client;


import com.hmall.api.client.fallback.ItemClientFallback;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * 商品服务openfeign远程调用客户端
 */
@FeignClient(name = "item-service",
        fallbackFactory = ItemClientFallback.class)
public interface ItemClient {

    /**
     * openFeign就可以利用动态代理帮我们实现这个方法，
     * 并且向http://item-service/items发送一个GET请求，
     * 携带ids为请求参数，并自动将返回值处理为List<ItemDTO>
     *
     * @param itemIds
     * @return
     */
    @GetMapping("/items")
    List<ItemDTO> queryItemByIds(@RequestParam("ids") Collection<Long> itemIds);

    @PutMapping("/items/stock/deduct")
    void deductStock(@RequestBody List<OrderDetailDTO> items);
}
